package syntax;

//import com.modeliosoft.modelio.javadesigner.annotations.objid;
//@objid ("0071b3bc-dfd3-10da-ac48-082e5f2773a2")
public class ClockConditionAtom implements Comparable<ClockConditionAtom>, Cloneable{
    //@objid ("002c3936-e16c-10da-ac48-082e5f2773a2")

    private Domain domain;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        ClockConditionAtom res = new ClockConditionAtom((Domain) domain.clone(), clock, lowerRelation, upperRelation);
        return res;
    }
    //@objid ("000629a8-e1b9-10da-ac48-082e5f2773a2")
    private Clock clock;
    //@objid ("002c3468-e208-10da-ac48-082e5f2773a2")
    private Operator.Op lowerRelation;
    //@objid ("00547cd4-e20b-10da-ac48-082e5f2773a2")
    private Operator.Op upperRelation;

    public ClockConditionAtom(Domain domain, Clock clock, Operator.Op lowerRelation, Operator.Op upperRelation) {
        this.domain = domain;
        this.clock = clock;
        this.lowerRelation = lowerRelation;
        this.upperRelation = upperRelation;
    }
    public ClockConditionAtom(Float l_b, Float u_b, Clock clock, Operator.Op lowerRelation, Operator.Op upperRelation) {        
        this.domain = new Domain(l_b, u_b);
        this.clock = clock;
        this.lowerRelation = lowerRelation;
        this.upperRelation = upperRelation;
    }

    
    public ClockConditionAtom() {
        domain = new Domain(0, parameters.Parameters.getInfinity());
        lowerRelation = Operator.Op.LT;
        upperRelation = Operator.Op.LT;
    }
    
    

    public Domain getDomain() {
        return domain;
    }

    public void setDomain(Domain domain) {
        this.domain = domain;
    }

    public Clock getClock() {
        return clock;
    }

    public void setClock(Clock clock) {
        this.clock = clock;
    }

    public Operator.Op getLowerRelation() {
        return lowerRelation;
    }

    public void setLowerRelation(Operator.Op lowerRelation) {
        this.lowerRelation = lowerRelation;
    }

    public Operator.Op getUpperRelation() {
        return upperRelation;
    }

    public void setUpperRelation(Operator.Op upperRelation) {
        this.upperRelation = upperRelation;
    }

    public boolean isSatisfied(Float v) {
        boolean res;
        float l_b = domain.getL_b(), u_b = domain.getU_b();
        res = (v < l_b) || (v > u_b);
        if (res) {
            return false;
        }

        if (((v==l_b) && (lowerRelation == Operator.Op.getLT())) || 
                ((v==u_b) && (upperRelation == Operator.Op.getLT()))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return  "" + (domain.getL_b()) + 
                lowerRelation + 
                clock.getName()  + 
                upperRelation + 
                domain.getU_b();
    }

    @Override
    public int compareTo(ClockConditionAtom t) {
        int res = 0;
        res = clock.compareTo(t.getClock());
        if (res!=0) {
            return res;
        }
        res = (int) ((int)(domain.getL_b()) - (int)(t.getDomain().getL_b()));
        if (res!=0) {
            return res;
        }
        res = (int) ((int)(domain.getU_b()) - (int)(t.getDomain().getU_b()));
        if (res!=0) {
            return res;
        }
        res = this.lowerRelation.compareTo(t.lowerRelation);
        if (res!=0) {
            return res;
        }
        res = this.upperRelation.compareTo(t.upperRelation);
        if (res!=0) {
            return res;
        }        
        return 0;
    }
    
}
